Beginners Programming
Demos
How to create a shortcut on the desktop with Windows XP.
This is a follow-up to the article by Gordon Rahman that was published in issue #119. I accidentally chopped off the end of his excellent article, so please add the article here to the one in issue #119. I apologize to everyone for the error, but especially to Gordon.
- Alyce Watson
The files and information from issue #119 are needed to complete this article.
Get Desktop Path
To place the shortcut on the desktop we need to find the path to where the desktop directory resides. Now here is a piece of the work of Alyce, Brent and others in detail.
'----------------------------------------------------------------------
'Get the desktop path function
CSIDL.DESKTOP = Hexdec("&H10")
struct IDL,cb As long, abID As short
desktop$ = GetSpecialfolder$(CSIDL.DESKTOP)
Print "Desktop folder: " + desktop$
wait
Function GetSpecialfolder$(CSIDL)
Open "shell32" For DLL As #sh
CallDLL #sh, "SHGetSpecialFolderLocation",_
0 As long, CSIDL As long, IDL As struct,_
ret As long
If ret=NOERROR Then
Path$ = Space$(512)
id=IDL.cb.struct
CallDLL #sh, "SHGetPathFromIDListA",_
id As long, Path$ As ptr, ret As long
Close #sh
GetSpecialfolder$ = Left$(Path$, Instr(Path$, Chr$(0)) - 1)
Else
GetSpecialfolder$ = "Error"
End If
End Function
'--------------------------------------------------------
' CSIDL.DESKTOP = &H0 ' The Desktop - virtual folder
' CSIDL.PROGRAMS = 2 ' Program Files
' CSIDL.CONTROLS = 3 ' Control Panel - virtual folder
' CSIDL.PRINTERS = 4 ' Printers - virtual folder
' CSIDL.DOCUMENTS = 5 ' My Documents
' CSIDL.FAVORITES = 6 ' Favourites
' CSIDL.STARTUP = 7 ' Startup Folder
' CSIDL.RECENT = 8 ' Recent Documents
' CSIDL.SENDTO = 9 ' Send To Folder
' CSIDL.BITBUCKET = 10 ' Recycle Bin - virtual folder
' CSIDL.TARTMENU = 11 ' Start Menu
' CSIDL.DESKTOPFOLDER = 16 ' Desktop folder
' CSIDL.DRIVES = 17 ' My Computer - virtual folder
' CSIDL.NETWORK = 18 ' Network Neighbourhood - virtual folder
' CSIDL.NETHOOD = 19 ' NetHood Folder
' CSIDL.FONTS = 20 ' Fonts folder
' CSIDL.SHELLNEW = 21 ' ShellNew folder
'CSIDL.DESKTOP = 23 ' Start Menu.
'------------------------------------------------------
Change this line CSIDL.DESKTOP = Hexdec("&H10") and see what happens.
You may use decimals instead of the hex values. So to find the path to Start Menu you can easily use
CSIDL.DESKTOP = 11. CSIDL.DESKTOP = 32 will reveal the Local Settings\Temporary Internet Files CSIDL.DESKTOP = 26 will reveal the Application Data,
Once you have the desired path, you need to attach the shortcut-file to it. So here is what you get.
shortcutName$ = desktop$ + "\" + shortcutName$ + ".lnk"
Mind the .LNK at the end.
If you combine the demo above with the demo I gave in last issue #118 (Xcopy), you should be able to create a very professional INSTALLER.
Gordon Rahman.